package main

func main()  {
	//将tee-channel传递给一个读channel，其会返回两个单独的channel，
	tee := func(
		done <-chan interface{},
		in <-chan interface{},
	) (_,_<-chan interface{}) {<-chan interface{}} {
	out1 := make(chan interface{})
	out2 := make(chan interface{})
	go func() {
	defer close(out1)
	defer close(out2)
	for val := range orDone(done,in) {
	var out1,out2 = out1,out2
	for i := 0;i<2;i++ {
	select {
	case <-done:
	case out1<-val:
	out1 = nil //写入channel后，将副本设置为nil，以便进一步阻塞写入
	case out2<-val
	out2 = nil
	}
	}
	}
	}()
	return out1,out2
	}

	done := make(chan interface{})
	defer close(done)

	out1,out2 := tee(done,take(done,repeat(done,1,2)),4)

	for val1 := range out1 {
	fmt.Printf("out1: %v,out2: %v\n",val1,<-out2)
	}


}


